<?php
/*
 * @Author: lokei
 * @Date: 2023-09-05 09:08:15
 * @LastEditors: lokei
 * @LastEditTime: 2023-09-05 13:49:46
 * @Description: 
 */

namespace App\Http\Controllers\Platform\Dy\Life;

use App\Common\Douyin\Common;
use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Store\StoreModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redis;

class VerifyController extends Controller
{
    public function submit(Request $request)
    {
        $access_token = Common::getAccessToken();
        $store = StoreModel::where('id', '=', $request->input('store_id'))->first();
        if ($store->poi_id != null && $store->poi_id != '') {
            $prepare_result = Common::prepareCertificate($access_token, null, $request->input('dy_code'));
            if ($prepare_result['data']['error_code'] == 0) {
                $verify_result = Common::verifyCoupon($prepare_result['data']['verify_token'], $access_token, $store->poi_id, null);
                if ($verify_result['data']['error_code'] == 0) {
                    $fields = array();
                    $fields['order_id'] = $request->input('order_id');
                    $fields['pid'] = config('app.proj_identity');
                    $fields['pay_mode'] = '3-2';
                    Redis::xAdd('pay_success', '*', $fields);
                } else {
                    $res = ResultTool::fail();
                    $res['errorMsg'] = $verify_result['data']['description'];
                    return $res;
                    return $res;
                }
            } else {
                $res = ResultTool::fail();
                $res['errorMsg'] = $prepare_result['data']['description'];
                return $res;
            }
        } else {
            $res = ResultTool::fail();
            $res['errorMsg'] = '未绑定抖店！';
            return $res;
        }
    }
}
